/**
 * tigerrad
 * fall 2006
 */

#ifndef _SDLWINDOW_H
#define _SDLWINDOW_H

#include "Util.h"
#include "Simulation.h"
#include "Engine.h"

const unsigned int SCREEN_BPP(16);

/**
 * A window utilizing SDL and OSG.  The SDLWindow will render the current OSG scene,
 * be it a menu or a level or whatever your heart desires.  The SDLWindow will
 * dispatch input and update events.
 */
class SDLWindow
{	
	public:
		/**
		 * Constructor.
		 * @param size Window width,height
		 * @param depth window bit depth
		 * @param fullscreen 
		 * @param resizeable can the user resize?
		 */
		SDLWindow(const Vec2s& size, GLuint depth, 
				bool fullscreen=false, bool resizeable=true);

		/**
		 * Set the Simulation that is the SDLWindow.
		 */
		void setSimulation(SimulationPtr s) { _sim = s; }

		/**
		 * Set the rendering Engine.
		 */
		void setEngine(EnginePtr e) { _engine = e; }

		/**
		 * Main rendering loop.
		 */
		void mainLoop();

		/**
		 * Toggle fullscreen on or off.
		 */
		void toggleFullscreen();

		/**
		 * true to output the fps
		 */
		void setShowFPS(bool fps) { _fps = fps; }

		/**
		 * Destructor.  
		 * Before exiting, jump out of fullscreen mode and 
		 * clean up SDL.
		 */
		virtual ~SDLWindow() { 
			if (_fullscreen) {
				toggleFullscreen();
			}
			SDL_Quit();
		}

	protected:
		Vec2s _size;
		GLuint _depth;
		SDL_Surface* _surface;
		int _videoFlags;
		bool _fullscreen;
		bool _resizeable;

		SimulationPtr _sim;
		EnginePtr _engine;

		bool _fps;
};

#endif

